﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace _09封装
{
    class Program
    {
        static void Main(string[] args)
        {
            //MyClass mc = new MyClass();
            
            //mc.Name = "xxx";

            //Console.WriteLine(mc.Name);
            //Console.ReadKey();
            
            //Do("张三", 18, "zs@yahoo.com");

            //进行一次全新的封装，把三个参数封装成一个参数
            MyArgs md = new MyArgs();
            md.Name = "lisi";
            md.Age = 20;
            md.Email = "lisi@yaohoo.com";
            Do(md);

            Console.ReadKey();

        }

        static void Do(string name, int age, string email)
        {
            Console.WriteLine(name + "   " + age + "    " + email);
        }

        //重载一下Do方法    这样就把多个参数封装成一个对象，只用传一个参数就可以了
        static void Do(MyArgs model)
        {
            Console.WriteLine(model.Name + "   " + model.Age + "   " + model.Email);
        }
    }

    class MyArgs
    {
        public string Name
        {
            get;
            set;
        }

        public int Age
        {
            get;
            set;
        }

        public string Email
        {
            get;
            set;
        }
    }


    class MyClass
    {
        private int _age = 19;
        private string _name;
        public string Name
        {
            get
            {
                if (_age > 2)
                {
                    return File.ReadAllText("uname.txt");
                        //_name;
                }
                return "太小没有名字，Baby";
            }
            set
            {
                if (value.Length > 5)
                {
                    throw new Exception("名字太长了");
                }
                else
                {
                    //_name = value;
                    File.WriteAllText("uname.txt", value);
                }
            }
        }
    }
}
